/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author 958024446
 */
import java.text.DecimalFormat;
public class OhmsLaw extends javax.swing.JFrame {

    /**
     * Creates new form OhmsLaw
     */
    public OhmsLaw() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        titleJLabel = new javax.swing.JLabel();
        vJLabel = new javax.swing.JLabel();
        voltsJTextField = new javax.swing.JTextField();
        voltsJLabel = new javax.swing.JLabel();
        rJLabel = new javax.swing.JLabel();
        resistanceJTextField = new javax.swing.JTextField();
        resistanceJLabel = new javax.swing.JLabel();
        iJLabel = new javax.swing.JLabel();
        currentJTextField = new javax.swing.JTextField();
        currentJLabel = new javax.swing.JLabel();
        controlJPanel = new javax.swing.JPanel();
        calculateJButton = new javax.swing.JButton();
        clearJButton = new javax.swing.JButton();
        printJButton = new javax.swing.JButton();
        quitJButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        titleJLabel.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        titleJLabel.setForeground(new java.awt.Color(102, 0, 0));
        titleJLabel.setIcon(new javax.swing.ImageIcon("zeus\\profile$\\958024446\\Desktop\\Java\\Labs\\OhmsFormula.jpg")); // NOI18N
        titleJLabel.setName("titleJLabel"); // NOI18N

        vJLabel.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        vJLabel.setText("V:");

        voltsJTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                voltsJTextFieldActionPerformed(evt);
            }
        });

        voltsJLabel.setText("volts");

        rJLabel.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        rJLabel.setText("R:");

        resistanceJTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resistanceJTextFieldActionPerformed(evt);
            }
        });

        resistanceJLabel.setText("ohms");

        iJLabel.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        iJLabel.setText("I:");

        currentJTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                currentJTextFieldActionPerformed(evt);
            }
        });

        currentJLabel.setText("amperes");

        controlJPanel.setLayout(new java.awt.GridLayout(2, 2));

        calculateJButton.setMnemonic('C');
        calculateJButton.setText("Calcualte");
        calculateJButton.setActionCommand("C");
        calculateJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                calculateJButtonActionPerformed(evt);
            }
        });
        controlJPanel.add(calculateJButton);

        clearJButton.setText("Clear");
        clearJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearJButtonActionPerformed(evt);
            }
        });
        controlJPanel.add(clearJButton);

        printJButton.setText("Print");
        printJButton.setEnabled(false);
        controlJPanel.add(printJButton);

        quitJButton.setText("Quit");
        quitJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quitJButtonActionPerformed(evt);
            }
        });
        controlJPanel.add(quitJButton);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(titleJLabel)
                .addGap(209, 209, 209))
            .addGroup(layout.createSequentialGroup()
                .addGap(167, 167, 167)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(controlJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rJLabel)
                            .addComponent(iJLabel)
                            .addComponent(vJLabel))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(resistanceJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(resistanceJLabel))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(voltsJTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(currentJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(voltsJLabel)
                                    .addComponent(currentJLabel))))))
                .addContainerGap(159, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(titleJLabel)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(vJLabel)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(voltsJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(voltsJLabel)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rJLabel)
                    .addComponent(resistanceJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(resistanceJLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(iJLabel)
                    .addComponent(currentJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(currentJLabel))
                .addGap(34, 34, 34)
                .addComponent(controlJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(45, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void voltsJTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_voltsJTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_voltsJTextFieldActionPerformed

    private void currentJTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_currentJTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_currentJTextFieldActionPerformed

    private void resistanceJTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resistanceJTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_resistanceJTextFieldActionPerformed

    private void quitJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitJButtonActionPerformed
        // Terminate the application
        System.exit(0);
    }//GEN-LAST:event_quitJButtonActionPerformed

    private void clearJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearJButtonActionPerformed
        // Clear all text fields to reset the form
        voltsJTextField.setText("");
        resistanceJTextField.setText("");
        currentJTextField.setText("");
        voltsJTextField.requestFocus();
    }//GEN-LAST:event_clearJButtonActionPerformed

    private void calculateJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calculateJButtonActionPerformed
        // Calculate the current given voltage and resistance
        DecimalFormat numberFormatter = new DecimalFormat("#,##0.0##");
        float volts, resistance, current;
        volts = Float.parseFloat(voltsJTextField.getText());
        resistance = Float.parseFloat(resistanceJTextField.getText());
        current = volts/resistance;
        currentJTextField.setText(numberFormatter.format(current));
    }//GEN-LAST:event_calculateJButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(OhmsLaw.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(OhmsLaw.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(OhmsLaw.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(OhmsLaw.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new OhmsLaw().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton calculateJButton;
    private javax.swing.JButton clearJButton;
    private javax.swing.JPanel controlJPanel;
    private javax.swing.JLabel currentJLabel;
    private javax.swing.JTextField currentJTextField;
    private javax.swing.JLabel iJLabel;
    private javax.swing.JButton printJButton;
    private javax.swing.JButton quitJButton;
    private javax.swing.JLabel rJLabel;
    private javax.swing.JLabel resistanceJLabel;
    private javax.swing.JTextField resistanceJTextField;
    private javax.swing.JLabel titleJLabel;
    private javax.swing.JLabel vJLabel;
    private javax.swing.JLabel voltsJLabel;
    private javax.swing.JTextField voltsJTextField;
    // End of variables declaration//GEN-END:variables
}
